/*
  HOJA DE TRABAJO 6
ListCircular.java
Fecha: 2 de Septiembre de 2011
Autor: Claudia Grajeda
Descripcion:


*/

import java.util.*;



public class ColaArreglo<T> implements Interface<T>{


	private List<T> cola1;
	private List<T> cola2;
	private List<T> cola3;
	private List<T> cola4;
	private T cola;
	private int num;
	
	public ColaArreglo(){
		cola1 = new ArrayList<T>();
		cola2 = new ArrayList<T>();
		cola3 = new ArrayList<T>();
		cola4 = new ArrayList<T>();
	}
	
	public T remove(T p) {
		if (cola1.get(0) == p){
			cola1.remove(p);
		}
		else{
			if (cola2.get(0) == p){
				cola2.remove(p);
			}
			else{
				if (cola3.get(0) == p){
					cola3.remove(p);
				}
				else{
					if (cola4.get(0) == p){
						cola4.remove(p);
					}
				}
			}
		}
		return p;
	}

	public int colaMenor(){
		if (cola1.size() <= cola2.size()){
			if (cola1.size() <= cola3.size()){
				if (cola1.size() <= cola4.size()){
					if (cola1.size() < 10){
						num = 1;
					}
				}
			}
		}
		else{
			if (cola2.size() <= cola1.size()){
				if (cola2.size() <= cola3.size()){
					if (cola2.size() <= cola4.size()){
						if (cola2.size() < 10){
							num = 2;
						};
					}
				}
			}
			else{
				if (cola3.size() <= cola1.size()){
					if (cola3.size() <= cola2.size()){
						if (cola3.size() <= cola4.size()){
							if (cola3.size() < 10){
								num = 3;
							}
						}
					}
				}
				else{
					if (cola4.size() <= cola1.size()){
						if (cola4.size() <= cola2.size()){
							if (cola4.size() <= cola3.size()){
								if (cola4.size() < 10){
									num = 4;
								}
							}
						}
					}
				}	
			}
		}
		return num;
	}
	
	public T getUltimo(){
		int n = colaMenor();
		if (n == 1){
			if (cola1.isEmpty() == false){
				cola = cola1.get(cola1.size()-1);
			}
			else cola = null;
		}
		if (n == 2){
			if (cola1.isEmpty() == false){
				cola = cola1.get(cola1.size()-1);
			}
			else cola = null;
		}
		if (n == 3){
			if (cola1.isEmpty() == false){
				cola = cola1.get(cola1.size()-1);
			}
			else cola = null;
		}
		if (n == 4){
			if (cola1.isEmpty() == false){
				cola = cola1.get(cola1.size()-1);
			}
			else cola = null;
		}
		return cola;
	}
	
	
	public void add(int n, T v){
		if (n == 1){
			cola1.add(v);
		}
		if (n == 2){
			cola2.add(v);
		}
		if (n == 3){
			cola3.add(v);
		}
		if (n == 4){
			cola4.add(v);
		}
	}
	
	/**
	 *toString: imprime el estado de las colas
	 */
	public String toString(){
		String descripcion = "";
		descripcion += "\n Cola 1: \n" ;
		descripcion += cola1.toString();	
		descripcion += "\n Cola 2: \n" ;
		descripcion += cola2.toString();
		descripcion += "\n Cola 3: \n" ;
		descripcion += cola3.toString();
		descripcion += "\n Cola 4: \n" ;
		descripcion += cola4.toString();
		return descripcion;
	}
}
